home *** CD-ROM | disk | FTP | other *** search
/ Risc World 3 / Risc World 3.iso / SOFTWARE / ISSUE3 / POWERBASE / DOCS / Ch04-Creat < prev    next >
Text File  |  2001-01-31  |  41KB  |  789 lines

  1. ==============================
  2. Ch 4 − Creating a New Database
  3. ==============================
  4.  
  5. Five steps are involved in setting up a new database:
  6.  
  7. (1)     Create the database application shell.         
  8. (2)     Design the record layout.         
  9. (3)     Specify the number of records the database is to contain.         
  10. (4)     Specify the primary key.         
  11. (5)     Build the empty database. 
  12.  
  13. 4.1     Creating the database application shell
  14. -----------------------------------------------
  15. You need to have Powerbase installed on the iconbar but with no database
  16. open, i.e. “No data” should appear under the icon. Click SELECT over the
  17. icon and a Save box will appear containing the default name !Database. Type
  18. in the name of your database and drag the icon to a directory window.
  19. Remember that, for RISC OS versions prior to 4.00, the name cannot exceed 10
  20. characters, including the initial “!”. If you enter more the name will be
  21. truncated and you could end up overwriting an existing database with a
  22. similar name. You don’t actually need to enter the “!”; Powerbase will
  23. insert it automatically.
  24.  
  25. If you open the newly-created application directory (Shift double-click) you
  26. will find that it contains four files (!Run, !Sprites, !Sprites22 and Data)
  27. and five directories (Indices, Menus, PrintJobs, PrintRes and ValTables). 
  28. All Powerbase databases expect these objects to be present so don’t delete
  29. any of them. 
  30.  
  31. 4.2     Designing the record layout
  32. -----------------------------------
  33. When you created the application shell you were left with a window on
  34. screen, blank apart from a grid of blue lines, and it is here that you must
  35. design the database record. This is the lengthiest part of setting up a
  36. database, although efforts have been made to render it as easy as possible.
  37. If you have closed the window just click SELECT on the Powerbase icon on the
  38. iconbar to re-open it. 
  39.  
  40. 4.2.1   Simple field creation
  41.  
  42. Clicking MENU over the window brings up the New database menu on which every
  43. item except Create field and Grid is shaded at this stage. Choosing Create
  44. field displays the Field Definition window which lets you specify the
  45. characteristics of a field. Grid allows you to choose options for the grid
  46. used to lay out the fields. This grid appears only at the design stage, not
  47. on a working database (except when using the Adjust format and New record
  48. format features). It may be turned off but you will probably find it a help
  49. in getting the field layout as you want it.  There are options to choose the
  50. colour of the grid, whether it is represented by solid or dotted lines and
  51. what the spacing between the lines is.  By default the grid has solid, light
  52. blue lines spaced 32 OS units apart and  fields will “snap” to it at
  53. intervals of 4 OS units.  The snap interval may be altered or the snapping
  54. disabled.  First decide what class of field you want to create. There are
  55. eight such classes, selected via radio buttons: 
  56.  
  57. (1)     Editable        (5)     Computed        
  58. (2)     Scrollable list (6)     Stamp
  59. (3)     Check-box       (7)     Keypad button
  60. (4)     External        (8)     Extra button
  61.  
  62. For the present we will confine ourselves to the first, which is the default
  63. selection. As well as the field class you must decide on the type of field
  64. within the class. The default offered is Unrestricted, meaning that it will
  65. accept all printable characters. We’ll look at other types later. 
  66.  
  67. Decide on a name for the field and enter it in the Descriptor icon. This is
  68. the name which will appear on the record window and may be up to 40
  69. characters long. You must also enter a Tag, which is used to identify the
  70. field in search formulae and is limited to 4 characters. Next enter the Data
  71. length; the maximum number of characters the field is to hold. Values up to
  72. 246 are allowed. Now click on Create and the field will appear on the record
  73. window. It’s probably not where you want it so use SELECT to drag the white
  74. rectangle to the position required. When you drop the field in its new
  75. position the descriptor falls into place too. If you want the descriptor
  76. somewhere other than to the left of the data icon (above it, for example) 
  77. move it by itself after positioning the data icon.  For fine adjustment
  78. re-open the Create window by double-clicking on the field and nudge the
  79. field into position using the bump icons at the bottom left corner.
  80.  
  81.                                 - 27 -
  82.  
  83. To edit an existing field you can either click MENU over the field and
  84. choose Edit field or simply double-click SELECT over the field itself as
  85. above.  You can also display the data for any field by clicking MENU
  86. anywhere in the window and choosing the field from the Fields Created
  87. submenu or by clicking the List fields button on the open dialogue box.
  88. After making changes click on Update (Create will be shaded).
  89.  
  90. 4.2.2   Deleting, inserting and re-ordering fields.
  91.  
  92. It is important to understand the difference between the physical position
  93. of fields on the screen and the internal numbering of the fields. The former
  94. is purely a matter of appearance and you may drag the fields about the
  95. screen to your heart’s content, but the latter is fundamental to the way the
  96. database will function.  Each field has a number which corresponds to the
  97. order in which it was created.  Whenever you invoke the Field Definition
  98. window the title-bar shows either the number of the (new) field you are
  99. about to create (e.g. “New field 3”) or the number of the (existing) field
  100. you were pointing at when you opened the menu (e.g. “Modify field 5”).  The
  101. numbering of fields determines the order in which they will be “visited” by
  102. the caret when you are actually using the database and typing Return to get
  103. from field to field, i.e. the editing order.
  104.  
  105. A field may be deleted by bringing it up for editing as described above and
  106. clicking on Remove field. Fields which come after the deleted field will
  107. then be found to have had their field-numbers reduced by 1.  Inserting a
  108. field into the middle of the existing field-sequence is obviously a little
  109. more complicated because we have to specify where in the sequence the new
  110. field goes.  You need to know the number of the field which you want to
  111. follow the new one. This number is entered in the before icon before you
  112. click on Create. The layout of this part of the window should make things
  113. clear: “Create before <n>”. If you examine fields which come after the
  114. insertion you will see that their numbers have increased by 1.
  115.  
  116. You can change the numbering of a field by removing it and then re-inserting
  117. it, but  there is a better way.  Bring the field up for editing as
  118. previously described. We will call this the “current field”. Enter the
  119. number of another existing field in the same place as was used above to
  120. specify the insertion position of a new field. We’ll call this the “entered
  121. field”. You may then do one of the following:
  122.  
  123. •       Click Swap with. This does exactly what you would expect. It swaps
  124.         the positions of the current field and the entered field in the
  125.         field sequence (but not their placement on-screen).
  126.  
  127. •       Click Renumber as.  This is a bit more complicated. The current
  128.         field acquires the number of the entered field. If this involves
  129.         giving the current field a lower number than previously the fields
  130.         beyond the new position are all moved up one place to open a gap for
  131.         it, at the same time closing up the gap left by moving the current
  132.         field from its old position. If it is being given a higher number
  133.         the fields above its old position all move down one place, closing
  134.         up the gap left by its removal and opening a gap in the required
  135.         place farther up the sequence. (Once again, the physical position of
  136.         the fields on the window is unchanged.)
  137.  
  138. 4.2.3   Moving and re-sizing the bounding box
  139.  
  140. Left to itself Powerbase makes all its field icons the same height and of a
  141. suitable length to contain the number of characters specified in Data
  142. length. This may not be quite what you want. If the data length is large the
  143. field could run off the right edge of the window. You might also want to
  144. make the field taller for emphasis. (But not for displaying multiple lines.
  145. Only fields of Text block type can be multi-line. These are discussed
  146. later.) 
  147.         
  148. We have already seen how you can alter the position of a field by dragging
  149. with SELECT. By dragging at an edge with ADJUST you can change the size of
  150. the bounding box.  
  151.  
  152. You can also specify both size and position by entering the required width
  153. and height of the bounding-box in the W and H icons and the co-ordinates of
  154. the lower-left corner in the X and Y icons of the Field creation window. All
  155. these values are in OS units (the same units as are used for plotting to the
  156. screen) but the origin is the top left corner of the record window. This
  157. means that the Y values are always negative.
  158.  
  159. Clicking on Fit automatically sets the bounding-box width to fit the data
  160. length.
  161.  
  162. 4.2.4   More about tags and descriptors
  163.  
  164. Tags are very important in Powerbase. They are used when querying the
  165. database to produce reports, export CSV files etc. and also by some internal
  166. operations. Every printable field (see 3.3) must have a tag and no two  tags
  167. can be the same. Descriptors are less important. They are there to provide
  168. visible labels for fields and in some cases you may not need one at all.
  169. e.g. You might want the record to look like this:
  170.  
  171.                                 - 28 -
  172.  
  173.            NAME Fred Bloggs 
  174.         ADDRESS 27, Every Street
  175.                 Anytown     
  176.                 Woolshire
  177.                 WL4 7XZ 
  178.  
  179. There are 5 fields here but, having given the second one the descriptor
  180. ADDRESS, you don’t really want descriptors for the remaining 3 (except
  181. perhaps POSTCODE for the last). It is quite in order to have null
  182. descriptors like this, but your must give each field a tag. Suitable ones
  183. might be NAME, ADD1, ADD2, ADD3, CODE. (Remember each must be unique and not
  184. more than 4 characters.)
  185.  
  186. You can omit the tag where the Data length is 0. This allows you to create
  187. fields which are simply explanatory labels. Since there is no data in them
  188. there would be no reason to include them in a query. 
  189.  
  190. 4.2.5   Other types of Editable field
  191.  
  192. So far we have only used fields of Unrestricted type. Clicking on bump icons
  193. to the left of the field type, or on the menu button to the right, lets you
  194. cycle through the various types available. These are:
  195.  
  196. (a)     Unrestricted    Accepts any printable character.
  197.  
  198. (b)     Alphanumeric    Accepts all letters and numerals and common
  199.                         punctuation.  
  200.  
  201. (c)     Upper case      Accepts capital letters and numerals only. 
  202.  
  203. (d)     Numeric Accepts numerals, +, − and . (decimal point).
  204.  
  205. (e)     Yes/No/Maybe    Accepts Y, N and ? only.
  206.  
  207. (f)     Date            Accepts dates in the form dd-mm-yy or dd-mm-yyyy,
  208.                         checking that the date is valid and reporting an
  209.                         error otherwise. 
  210.  
  211. (g)     Time            Accepts times in the form hh:mm:ss up to a value of
  212.                         23:59:59. The time is checked for validity and
  213.                         errors are reported. 
  214.  
  215. (h)     Internet        Special field for email addresses and web URLs.
  216.                         There is no restriction on character input, but
  217.                         double-clicking will call up your mail program
  218.                         or browser (if it has been “seen” by the filer) with
  219.                         the address loaded.
  220.  
  221. When Numeric is selected, certain icons in the dialogue box which are
  222. normally shaded become available. Thus, you can specify floating-point,
  223. fixed-point or integer format by means of a group of radio buttons. You may
  224. also specify a maximum and minimum value for numbers which may be entered in
  225. these fields. The Numeric min icon is also used to hold the starting value
  226. for Sequence number fields (see 4.2.10).
  227.  
  228. A Date field should be either 8 or 10 characters long in order to hold the
  229. date in one of the two formats specified above. The hyphen separator in
  230. these dates may be changed via the Preferences window (see 14.5.1). 
  231. Powerbase is very tolerant of the way you actually enter a date. You may
  232. type any non-numeric character as a separator: Powerbase will make sense of
  233. an entry such as 4/5/87, converting it to 04-05-87 when you type Return.
  234. Arithmetic may be performed on dates held in this type of field, e.g. you
  235. could have a Calculated field subtract the contents of two Date fields and
  236. display the difference in days (see 6.1.5).
  237.  
  238. Time fields also allow flexibility in how you enter the values. If you enter
  239. 3.45;9 it will be reformatted as 03:45:09. The colon separator may be
  240. changed via the Preferences window (see 14.5.1). You may also enter
  241. incomplete times which are, by default, interpreted as follows. A number
  242. entered on its own is treated as hours. Thus, if you enter 6 and type Return
  243. it will be reformatted as 06:00:00. Two number separated by a non-numeric
  244. character are treated as hours and minutes, e.g. 6/5 would be reformatted as
  245. 06:05:00. You may edit Powerbase’s Config file to reverse this behaviour so
  246. that 6 is formatted as 00:00:06 and 6/5 as 00:05:06. When using this mode of
  247. entry you may also suppress the hours part of the display for values less
  248. than an hour, e.g. so that 6/5 is formatted as 05:06. (See 14.6 for editing
  249. Config.)
  250.  
  251. Like Date fields, Time fields may be included in calculations, e.g. to
  252. obtain the difference in seconds between two times or to average a number of
  253. times (see 6.1.4).
  254.  
  255. 4.2.6   Scrollable lists
  256.  
  257. These are also user-editable but are treated separately because they are
  258. like no other editable field.  They are intended for record structures which
  259. contain closely-related data whose number might vary widely from one record
  260. to another. A music CD, for example, might have only 3 or 4 tracks but it
  261. could have 30 or more. If you are cataloguing CDs and including track
  262. information you don’t really want to define 30 separate fields to allow for
  263. just a few extreme records − and find even then that the odd disc has more
  264. than 30 tracks! A scrollable list lets you make allowance for a modest
  265. number of items, adding new ones as required for individual records. Since
  266.  
  267.                                 - 29 -
  268.  
  269. the list is scrollable it occupies no more space on the record window no
  270. matter how many items are in the list.
  271.  
  272. You may create this type of field with anywhere from 1-4 columns. The value
  273. entered in Data length is the column width, i.e. the number of characters
  274. which each cell can hold. All columns are normally of the same width (but
  275. see below for how to specify differing widths). When you click Create all
  276. that appears is a plain white rectangle: not until you complete the process
  277. of creating the database does it appear with the cells and vertical
  278. scroll-bar characteristic of this type of field. The height of this
  279. rectangle will determine the height, and hence the number of visible rows,
  280. in the list. By default it will accommodate 3 rows but you may drag with
  281. ADJUST to make it higher. When you release the mouse button the rectangle
  282. will snap to a height which exactly fits the nearest whole number of rows.
  283.  
  284. As noted above, you can make the columns differ in width. The field is
  285. created as above and the other steps to produce a working database are
  286. carried out. You then need to create a little text file called Format
  287. containing the individual column widths, one to a line. There must be as
  288. many numbers as columns and the sum of the new column widths must be exactly
  289. the same as it was before. Suppose you had created a 3-column scrollable
  290. list with a Data length of 10, giving 3 columns, each capable of holding 10
  291. characters. This means you have 30 characters to play with. You can put into
  292. Format the numbers 5, 15, 10 or 3, 7, 20 or any other 3 numbers which add up
  293. to 30. Where do you put the Format file? Open the database directory
  294. (Shift-double-click) and look for a subdirectory called Scroll<n>, where n
  295. is the field number of the scrollable list. Format should go in this
  296. subdirectory.
  297.  
  298. The data contained in scrollable lists is not held in the Database file.
  299. Data for each record is in a separate file stored in a special system of
  300. subdirectories inside the database directory. In this they resemble External
  301. fields (see 4.2.8)
  302.  
  303. 4.2.7   Check-box fields
  304.  
  305. These are fields whose status changes when clicked on with SELECT. Five
  306. types are defined:
  307.  
  308. (a)     Cross/tick      Displays a cross initially. A click changes it to a
  309.                         tick. A second click changes it back to a cross.         
  310.  
  311. (b)     Null/tick       Similar to (a), but initial state is an empty box.         
  312.  
  313. (c)     Null/star       Similar to (b), but second state is a star.
  314.  
  315. (d)     Null/tick/cross This is a three state check box the first state
  316.                         being an empty box.
  317.  
  318.                         Repeated clicking cycles through tick, cross and
  319.                         back to empty box.
  320.  
  321. (e)     ?/tick/cross    Another three-state check-box where the first is a
  322.                         question mark.
  323.  
  324. Check-boxes provide the fastest way of entering true/false or yes/no type
  325. data and the 3-state types allow for yes/no/undecided situations. If you
  326. examine the ValStrings file inside !Powerbase.Resources you will find
  327. strings associated with each of these five types the latter parts of which
  328. read, respectively:
  329.  
  330.         QNo,Yes     Q-,Yes      Q-,*     QNo,Yes,-     QNo,Yes,?       
  331.  
  332. These specify what will actually appear in a print-out when a check-box
  333. field is included in a query (see 3.3). You may change them if you wish, but
  334. don’t omit the initial Q (although this will not appear in the print-out)
  335. and take care not to alter other parts of the string.
  336.  
  337. 4.2.8   External fields
  338.  
  339. External fields allow you to link Powerbase records to pieces of data of a
  340. size and type which make them unsuitable for inclusion in an Editable field.
  341. Such items are sometimes called “BLOBs” (Binary Large Objects) in the PC
  342. world. The field types in this class and the types of data linked to them
  343. are as follows: 
  344.  
  345. (a)     Text            Plain text files, such as Edit creates.
  346. (b)     Sprite          Sprite files, such as Paint creates.         
  347. (c)     Draw            Drawings such as Draw creates. 
  348. (d)     Text block      Plain text files, as for (a). 
  349. (e)     Picture         Sprite files, as for (b).
  350. (f)     Remote          Anything!
  351.  
  352. When you create a field of type Text, Sprite or Draw it appears on the
  353. record window as a button bearing a small version of the icon for Edit,
  354. Paint or Draw respectively. Files of the appropriate type may be dropped on
  355.  
  356.                                 - 30 -
  357.  
  358. these buttons, whereupon the file is copied into a special system of
  359. subdirectories within the database application. Unlike fields of the
  360. Editable class the data doesn’t become part of the Database file within the
  361. application (see also 4.2.6); the Text, Sprite or Draw file retains its
  362. identity and may be exported for editing in the appropriate application.
  363. Clicking on the button in the record window will display the file if the
  364. filer knows the whereabouts of the relevant editor (Edit, Paint or Draw). 
  365.  
  366. Text block and Picture fields take things a step further by actually
  367. displaying a text or sprite file on the record window. The bounding box of
  368. the icon needs to be of suitable size to hold the text or sprite. In the
  369. case of a Text block too small a box will cause the text to appear
  370. truncated. None is actually lost; it just can’t all be displayed. Too small
  371. a box for a Picture field will cause the sprite to spread beyond its
  372. boundaries. (N.B. To display the same sprite on each record, e.g. a company
  373. logo, define the field as of type Logo, not Picture.)  the contents of a
  374. Text block or Picture field can be loaded into Edit or Paint by
  375. double-clicking with SELECT.  When the edited text or sprite is saved the
  376. Powerbase field will be seen to update.
  377.  
  378. Remote fields allow any type of filer object (file, directory or
  379. application) to be linked to a button on the record window. They differ from
  380. Text, Sprite, and Draw buttons in that the linked object is not copied into
  381. the database directory; only its pathname is stored, hence the term
  382. “Remote”. This has both advantages and disadvantages. Because no copy is
  383. made disc space is saved and the database stays a manageable size; an
  384. important factor where large sprites are involved.  On the other hand, if
  385. you transfer the database to another computer all references to the linked
  386. objects become invalid and might even cause retrieval of files which are
  387. quite different from the ones you originally attached to the records! 
  388. Similarly, if you move a linked object to some other part of your hard disc
  389. the pathname stored by Powerbase will no longer be correct.
  390.  
  391. A Remote button normally shows a large, down-pointing arrow inviting the
  392. user to drop an object onto it. It will accept files of any type, ordinary
  393. directories or applications. Once a link is established the button shows the
  394. appropriate file icon or a blue folder or the default application icon. A
  395. single click has the same effect as double-clicking the object in a filer
  396. window: directories are opened, applications are run, files are loaded into
  397. their applications, Obey files and Basic programs are executed. If the
  398. linked object can’t be found Powerbase will be aware that something used to
  399. be there and the button will display a question mark. 
  400.  
  401. If you wish to break the link between button and file object click MENU over
  402. the button, go to the Field submenu and choose Unlink object.  The button
  403. will revert to its original down-pointing arrow icon.
  404.  
  405. The uses of this field type are limitless. You can use it to catalogue your
  406. collection of GIFs, JPEGs, sound samples, Sibelius files, Impression
  407. documents or whatever. You could even use it as an application launcher,
  408. although I’m sure there are more convenient ones available!  
  409.  
  410. The full pathname of a Remote object is stored in the database. Since RISC
  411. OS allows pathnames up to 255 characters long they can occupy rather a lot
  412. of space in a large database. Powerbase does allow you to specify a maximum
  413. pathlength of less than 255 characters but you must be very careful when
  414. using it. The value is set in the !Powerbase.Resources.Config file and is
  415. called PathLen. When an empty database is created it will use whatever value
  416. of PathLen is currently configured and it may not subsequently be changed
  417. without a complete reformat of the database. Be wary, therefore, about
  418. reducing the default value of 255 characters. Since, however, it is now
  419. possible for databases to have Config files of their own it would be far
  420. better to place any lower value of PathLen in such a file and leave
  421. Powerbase’s default at 255. Any attempt to store an overlong pathname in a
  422. Remote field will be rejected with an error message.
  423.  
  424. 4.2.9   Computed fields
  425.  
  426. Discussion of Computed fields is postponed to Ch 6 − Performing
  427. Calculations.
  428.  
  429. 4.2.10  Stamp fields
  430.  
  431. Stamp fields resemble Computed fields in that you cannot edit them;
  432. Powerbase “stamps”  the fields with the appropriate contents automatically.
  433. The following types are available:
  434.  
  435. (a)     Record number   Database record number.         
  436.  
  437. (b)     Sequence number Unique value numbered upwards from base value set by
  438.                         user.
  439.  
  440. (c)     Time            Time at which record was created.         
  441.  
  442. (d)     Date            Date on which record was created.         
  443.  
  444. (e)     Date and time   Date and time of record creation.         
  445.  
  446. (f)     Day             Day on which record was created (in the form Sun,
  447.                         Mon etc or 1,2 etc. or day of month as 10, 24 etc).
  448.  
  449.                                 - 31 - 
  450.  
  451. (g)     Month           Month in which record was created (as either a
  452.                         string; Jan, Feb etc or a number; 1, 2 etc). 
  453.  
  454. (h)     Year            Year when record was created as four-digit number,
  455.                         e.g. 1993
  456.  
  457. (i)     Last altered    Records the date and time record is first created
  458.                         and updates it only 
  459.  
  460.                         if the record is subsequently altered. Merely
  461.                         displaying the record does not cause updating.         
  462.  
  463. (j)     Logo            Allows a sprite to be included as a logo on  every
  464.                         record.
  465.  
  466. These fields are stamped by Powerbase when a record is first entered and
  467. thereafter, with the exception of (i), stay fixed. (But see Ch.6 for similar
  468. types of field which auto-update.) Note the following:
  469.  
  470. •       When defining Record or Sequence number fields make sure the Data
  471.         length icon contains a large enough value to accommodate the longest
  472.         number which will be encountered. For the other types the required
  473.         field length is already known by Powerbase and the Data length box
  474.         is therefore shaded.
  475.  
  476. •       The base value from which sequence numbers begin is entered in the
  477.         Numeric min box. When a record containing such a field is deleted
  478.         the sequence number is not normally re-used; a new record is given a
  479.         new sequence number.  This, of course, leads to gaps in the numeric
  480.         sequence and you might want to reassign the numbers so that the
  481.         sequence is continuous.  You can do so by means of Compact sequence
  482.         from the Field submenu. Before this can be used the sequence number
  483.         field must be indexed and selected as the current index.   
  484.  
  485. •       Date fields may display the date in any of three formats:
  486.  
  487.         (1)     Sun,01 Aug 1993 (called “Long date”)         
  488.         (2)     01-08-93        (called “Date 8”)         
  489.         (3)     01-08-1993      (called “Date 10”) 
  490.  
  491. (2) and (3) are identical to the formats in which Powerbase displays dates
  492. of the ordinary Editable type (see 4.2.5). The numbers refer to the field
  493. length occupied by the date stamp.
  494.  
  495. •       Logo fields require the name of the sprite to be entered as the tag
  496.         of the field to be used as a logo. This means that the sprite name
  497.         is limited to four characters. The icon for a Logo field (like that
  498.         of a Picture field) must be large enough to hold the intended
  499.         sprite. You may have several logo fields on your record, all the
  500.         required sprites being included in a sprite file called UsrSprites
  501.         which is placed inside the database directory.
  502.  
  503. 4.2.11 Button fields
  504.  
  505. Any or all of the control buttons on the Powerbase keypad may be made to
  506. appear on the record window itself. They have exactly the same functions as
  507. the keypad equivalents. These button fields let you build a customised
  508. database which allows the user to use only the features you want him/her to
  509. have access to since the keypad and menus can then be suppressed (see 11.2).
  510. There is also a group of Extra buttons which have no keypad equivalent:
  511.  
  512. Print brings up the Match window for report printing. Print button (on
  513. screen)  
  514.  
  515. Exit duplicates the action of Close database on the iconbar menu. Exit
  516. button 
  517.  
  518. Quit duplicates the action of Quit on the iconbar menu. Quit button  Run
  519. file button, unlinking 
  520.  
  521. Run file. This type of button displays an icon made up of four different
  522. filetype icons. When you drop a file onto the button the icon changes to
  523. that of the relevant file and subsequent clicks on the button will run the
  524. file. Text files are treated as Powerbase scripts (see Ch 12), other types
  525. of file (e.g. Obey files) have their normal Run action. It is important to
  526. appreciate the difference between this type of button and a Remote field
  527. button (see 4.2.8). The file associated with a Remote field belongs to a
  528. specific record and every record can have a different file. The file
  529. attached to a Run file button is the same whatever record is being displayed
  530. and merely provides a convenient means of executing the file.  To break the
  531. link with the file click MENU over the button, go to the Field submenu and
  532. choose Unlink file. The name of the file, if required, may be given in the
  533. descriptor or the leafname may be made to appear on the button by editing
  534. the Config file.
  535.  
  536.                                 - 32 -
  537.  
  538. Directory. This resembles the previous type. In its initial state the button
  539. displays the small directory icon. Dropping a directory onto it changes this
  540. to a large directory icon and clicking on the button opens a filer window on
  541. the directory.  To break the link with the directory click MENU over the
  542. button, go to the Field submenu and choose Unlink directory. Options in the
  543. Config file allow you to determine what the filer window looks like; the
  544. default being small icons and alphabetic sorting. The leafname may be
  545. displayed on the button. Without it you could confuse Directory and Run file
  546. buttons with Remote fields.
  547.  
  548. Menu. This button lets you associate a data field with a pop-up menu. 
  549. Clicking the button and choosing a character string from the menu enters it
  550. into the data field. The field number of the data field is entered as the
  551. tag of the menu button. This happens automatically if you define the button
  552. immediately after the data field.  The menu data is in a text file whose
  553. name is the tag of the associated data field plus the word “Menu”. Put the
  554. menu title on the first line of the file and each menu choice on a separate
  555. line.  All user-menu files are stored in the Menus subdirectory inside the
  556. database directory. If you click on a Menu button without having constructed
  557. the relevant menu file you will be given appropriate instructions.
  558.  
  559. 4.2.12 Mandatory fields
  560.  
  561. This isn’t yet another class of fields. A mandatory field is one which must
  562. be filled in before you can access another record or close the database. It
  563. has already been noted that at least one of the primary key fields must not
  564. be blank (see 2.4.1), but any Editable field (but not Scrollable list) can
  565. be made mandatory by selecting the Must not be blank option button when
  566. designing the field. Such fields appear on a working database with red as
  567. the foreground colour. (This may be altered via the Colours window; see
  568. 14.5)
  569.  
  570. 4.3     A short-cut to a working database
  571. -----------------------------------------
  572. The third item on the New database menu is called Default database. Choosing
  573. this is by far the quickest way of getting a database up and running. Its
  574. action is to create three files inside the application directory. These are
  575. called Form (which holds the record design), PrimaryKey and Database (which
  576. will ultimately contain the entered records). The number of records in the
  577. database is set to 100, with 25 as the amount by which this should increase
  578. when the database becomes full. The primary key is defined as the first four
  579. characters of the first Editable field. The database is opened and a blank
  580. record displayed ready for data entry.  Since you can always alter such
  581. things as the database size and primary key structure later, you might wish
  582. to use these defaults while you experiment with the database.
  583.  
  584. If you want to choose the database size and primary key structure yourself
  585. follow the procedure in Sections 4.4 and 4.5
  586.  
  587. 4.4     Specifying the database size
  588. ------------------------------------
  589. This involves two steps:
  590.  
  591. (1)     Save the Form file (which contains all the field data). The Save
  592.         form file menu entry leads to a standard Save box but, since the
  593.         pathname is correctly set for saving the file inside your database
  594.         application, all you actually need do is click on the menu item
  595.         itself. 
  596.  
  597. (2)     You will now see that the Database size choice is no longer shaded
  598.         and may be used to reach the Size window in which you specify the
  599.         number of records in the database and the increment for expanding
  600.         the database when it becomes full. 
  601.  
  602. 4.5     Specifying the primary key
  603. ----------------------------------
  604. 4.5.1   General procedure
  605.  
  606. Click MENU and choose Primary key.  This opens the Key Structure window. The
  607. primary key (or any other key) is derived from one or more record fields
  608. called key fields. Up to four key fields may be used to define a key but we
  609. will begin by using just one.  Four pieces of information need to be
  610. specified:
  611.  
  612. (1)     Choose the field, either by clicking on the bump icons or choosing
  613.         from the associated pop-up menu.  The default is the first Editable
  614.         field in the record.
  615.  
  616. (2)     Enter the word within the field from which characters are to be
  617.         taken to make up the key.  The default is word 1.  If 0 is entered
  618.         word boundaries are ignored (see 4.5.2).
  619.  
  620. (3)     Enter the position within the word from which characters are to be
  621.         taken. L (default) means from start of word, R means take from end. 
  622.         A number (n) means start at the nth character.
  623.  
  624.                                 - 33 -
  625.  
  626. (4)     Enter the number of characters to be taken from the word. The
  627.         initially-set value is 4 but thereafter the default is the defined
  628.         field length. 
  629.  
  630. After entering this information click on Create and the empty Database and
  631. PrimaryKey files will be created, after which the database will open ready
  632. for you to start entering records.
  633.  
  634. 4.5.2   Some illustrative examples      
  635.  
  636. Key fields should be chosen with care. An ideal key field is one whose
  637. contents would never be repeated in another record. Powerbase lets you
  638. enforce this condition if you wish (see 11.2.1) but the default setting
  639. allows key duplication. Occasional repetitions may not be serious, but a
  640. field which can have only a few “values” is usually a poor choice. A
  641. customer number or membership number is the sort of thing we are looking for
  642. but your database may not contain anything like that.  In a database of
  643. school pupils the pupil’s name would be a good choice of key, but the form
  644. teacher’s name would not, since only a small number of names would be
  645. involved, each appearing on the record of many pupils. 
  646.  
  647. Suppose you decide to use a person’s name, stored surname first, in a single
  648. field whose tag is NAME, as a key. You could use the whole name but it would
  649. probably be too long. The first four letters would be more appropriate but,
  650. as this is the start of the surname, you might get a lot of duplication.
  651. e.g. PRESTON and PRESCOTT would both have the key PRES; and this is before
  652. we even consider people whose surnames are identical. To get round this
  653. problem, Powerbase lets you construct an alphanumeric key from characters
  654. taken from up to four successive words. You will seldom need to go so far.
  655. In the present case a five-letter key made up from the first four letters of
  656. the surname and one letter of the forename would be good enough for most
  657. purposes. 
  658.  
  659. Set up the Key Structure window as follows:
  660.  
  661.                         Field   Word            Position        Chars
  662.  
  663.         1st row:        NAME    1               L               4
  664.         2nd row:        NAME    2               L               1
  665.  
  666. This works quite well.  Smith Peter and Smith Janet would have the keys
  667. SMITP and SMITJ. Duplication can still occur, but not often enough to be a
  668. serious problem.
  669.  
  670. Further examples illustrate the use of letters from different parts of words
  671. in the key field.  The following settings of word, position and characters
  672. would produce the keys shown from the name Herring Albert.  (a)­(d) use the
  673. Surname only, (e) and (f) use the Forename only, the rest use both names:
  674.  
  675.         From Surname             From Forename
  676.  
  677.      Word   Pos   Chars      Word   Pos   Chars   Key
  678.  
  679. (a)   1      L      5         -      -      -     HERRI 
  680. (b)   1      R      4         -      -      -     RING 
  681. (c)   1      2      3         -      -      -     ERR 
  682. (d)   1      4      6         -      -      -     RING    (stops at word end) 
  683. (e)   -      -      -         2      L      3     ALB 
  684. (f)   -      -      -         2      R      4     BERT 
  685. (g)   1      L      4         2      L      4     HERRALBE 
  686. (h)   2      L      3         1      R      3     ALBING 
  687. (i)   1      4      3         2      4      2     RINER    
  688. (j)   0      R      7         -      -      -     GALBERT (ignores breaks) 
  689. (k)   -      4      6         -      -      -     RINGAL  (ignores breaks)
  690.  
  691. Take particular note of what happens if the word number is entered as 0 (or
  692. left blank).  All breaks between words are then ignored.  The field is
  693. treated as if the blanks between words had been removed leaving a single
  694. long word which is then subjected to the process specified by the position
  695. and characters icons.  When, on the other hand, the word number is 1 or
  696. greater the scanning for characters stops when the end of the word is
  697. reached so that the key might be shorter than the character length
  698. specified. Example (d) illustrates this.  
  699.  
  700. 4.5.3   Using more than one field in a key
  701.  
  702. You might, of course, want to store surname and forename in different
  703. fields. Let’s call their tags SNAM and FNAM.  To produce the five-letter
  704. keys given in our first example the key definition would be:
  705.  
  706.                                 - 34 -
  707.  
  708.                         Field   Word        Position          Chars
  709.  
  710.         1st row:        SNAM    1               L               4
  711.         2nd row:        FNAM    1               L               1
  712.  
  713. and the keys generated will be exactly the same as they would be for the
  714. single field NAME.
  715.  
  716. There are databases where no single field is suitable for constructing the
  717. primary key.  In a database of classical music, for example, there would
  718. probably be one field for the composer’s name and one for the name of the
  719. work. Neither is much use individually; the former could contain many
  720. occurrences of Mozart or Beethoven and the latter many repetitions of
  721. Symphony No. 5 or String Quartet in D minor. 
  722.  
  723. This is the kind of situation where you might want to use two fields and as
  724. many as four words, taking one word from the Composer field and three from
  725. the Work field using, say, 4, 3, 3 and 2 characters respectively from them. 
  726. The following two works then give the keys shown (characters taken from the
  727. left in each case):
  728.  
  729.         BEETHOVEN  Symphony No 5:               BEETSYMNO5                 
  730.         MOZART Piano concerto 23:               MOZAPIACON23 
  731.  
  732. Note the following points in these examples:              
  733.  
  734. (a)     If a word is shorter than the number of letters assigned to it (“No”
  735.         in the first example) then the whole word is used but no padding is
  736.         inserted.
  737.  
  738. (b)     It may be necessary to omit an insignificant word (“No” in the
  739.         second example), in order to make a significant one (“23”) come in
  740.         the first four words of the combined key fields. 
  741.  
  742. NOTE It is not usually sensible to build up keys derived from Numeric fields
  743. out of separate bits in this way and, indeed, Powerbase won’t allow you to
  744. do so. Numeric keys should use one key-field only, the key being the actual
  745. numeric value of the field contents.
  746.  
  747. 4.5.4   Other matters concerning keys   
  748.  
  749. We have already noted that a word shorter than the number of characters
  750. specified is used just as it is, resulting in a short key. There might be
  751. times when you want short words padding out with spaces to give a key of
  752. full length and there is a switch to select this action in the Key Structure
  753. window.
  754.  
  755. A final factor to be decided is whether the indexing is to pay attention to
  756. the case of letters, i.e. if they are capitals or small letters By default
  757. indexing is not case-sensitive. Thus if a record has the word “Horse” as the
  758. contents of a key field and the first four letters are used as the key then
  759. the entry in the index will be “HORS” and you may search for it by entering
  760. “HORS”, “hors”, “Hors”, “hOrS” etc.
  761.  
  762. This may not be what you want. If you require indexing to be case sensitive
  763. select the switch labelled Case. Forcing to upper case as described above
  764. does not then take place: keys are inserted and strings are searched for “as
  765. is”. The field containing “Horse” will be indexed as “Hors” and only that
  766. precise combination of upper and lower case letters will successfully find
  767. it. 
  768.  
  769. Alphanumeric keys will be ordered according to the ASCII values* of the
  770. letters. Since lower-case letters come later in the ASCII table than
  771. upper-case ones a record containing “dog” would appear after one containing
  772. “Horse”, whereas one containing “Dog” would come before “Horse”. 
  773.  
  774. 4.6     Building the empty database
  775. -----------------------------------
  776. Once you are satisfied click Create and blank Database and PrimaryKey files
  777. will be created. The record window is redrawn and you may start entering
  778. data at once.
  779.  
  780. 4.7     Renaming a database
  781. ---------------------------
  782. Use the Rename database option on the Miscellaneous submenu to do this.  If
  783. you rename via the filer your database will lose its ‘PB’ icon and revert to
  784. the default application icon (‘APP’ with Archimedes ‘A’, or 2 large
  785. exclamation marks if you have RISC OS 4). Rename database is duplicated on
  786. the iconbar menu so that you can rename at the record-design stage. 
  787.  
  788.                                 - 35 -   
  789.